package com.ruoyi.vote.app.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.vote.admin.domain.bo.WxUserSubBo;
import com.ruoyi.vote.admin.domain.vo.WxUserSubVo;
import com.ruoyi.vote.admin.service.IWxUserSubService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * API - 消息订阅
 * @author 立勤
 * @date 2023/07/25 19:15:04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/message")
public class ApiSubMessageController extends BaseController {

    private final IWxUserSubService iWxUserSubService;

    /**
     * 查询用户订阅列表
     */
    @GetMapping("/query-temp-list")
    public TableDataInfo<WxUserSubVo> queryTempList(WxUserSubBo bo, PageQuery pageQuery) {
        bo.setOpenid(LoginHelper.getLoginUser().getOpenid());
        return iWxUserSubService.queryPageList(bo, pageQuery);
    }

    /**
     * 添加活动订阅信息
     */
    @PostMapping("/put-sub-temp")
    public R<Void> putSubTemp(@Validated(AddGroup.class) @RequestBody WxUserSubBo bo) {
        return toAjax(iWxUserSubService.insertByBo(bo));
    }

}
